import { BasicFetchResult } from '../../model/baseModel';
import { defHttp } from '@/utils/http/axios';
import { downloadBlob } from '@/utils/file/download';
enum Api {
  ReportDataSetApi = '/reportDataSet',
}
/**
 * 查询数据集管理分页
 * @author frank
 * @date 2023-04-11 17:46:08
 */
export const page = (params?: any) =>
  defHttp.get<BasicFetchResult<any>>({
    url: Api.ReportDataSetApi + '/page',
    params,
  });
export const testData = (params: any) =>
  defHttp.post<BasicFetchResult<any>>({
    url: `${Api.ReportDataSetApi}/testScript`,
    params,
  });
/**
 * 添加数据集管理
 * @author frank
 * @date 2023-04-11 17:46:08
 */
export const add = (params?: any) =>
  defHttp.post({ url: Api.ReportDataSetApi + '/add', params });
/**
 * 修改数据集管理
 * @author frank
 * @date 2023-04-11 17:46:08
 */
export const edit = (params?: any) =>
  defHttp.post({ url: Api.ReportDataSetApi + '/edit', params });

/**
 * 删除数据集管理
 * @author frank
 * @date 2023-04-11 17:46:08
 */
export const del = (ids: string[]) =>
  defHttp.post({ url: Api.ReportDataSetApi + '/delete', params: ids });
/**
 * 导出数据集管理
 * @author frank
 * @date 2023-04-11 17:46:08
 */
export const exp = (params?: any) => {
  return new Promise<void>((resolve, reject) => {
    defHttp
      .get(
        { responseType: 'blob', url: Api.ReportDataSetApi + '/export', params },
        { isReturnNativeResponse: true }
      )
      .then((res) => {
        downloadBlob(res);
        resolve();
      })
      .catch(() => {
        reject();
      });
  });
};
/**
 * @param params setCode数据集code
 * @returns
 */
export const getData = (params?: any) =>
  defHttp.get<BasicFetchResult<any>>({
    url: Api.ReportDataSetApi + '/getData',
    params,
    timeout: -1
  });
export const expSetData = (params?: any) => {
  return new Promise<void>((resolve, reject) => {
    defHttp
      .get(
        {
          responseType: 'blob',
          url: Api.ReportDataSetApi + '/getData',
          params,
          timeout: -1
        },
        { isReturnNativeResponse: true }
      )
      .then((res) => {
        downloadBlob(res);
        resolve();
      })
      .catch(() => {
        reject();
      });
  });
};
/**
 * 数据集参数列表
 */
export const paramsList = (dataSetId?: string) =>
  defHttp.get<BasicFetchResult<any>>({
    url: '/reportDataSetParam/list',
    params: { dataSetId },
  });

export const editParams = (params: string) =>
  defHttp.post<BasicFetchResult<any>>({
    url: '/reportDataSetParam/edit',
    params,
  });
